
#ifndef  _RADIX_ARCHAISM_TIME_H_
#define  _RADIX_ARCHAISM_TIME_H_

#include <Archaism/Header.h>
#include <ctime>

_BeginNamespace(Radix)
/*
============================================================
== TimeSpan
============================================================
*/
class TimeSpan
{
public:
	static const longlong kUsecsPerMsec;
	static const longlong kUsecsPerSecond;
	static const longlong kUsecsPerMinute;
	static const longlong kUsecsPerHour;
	static const longlong kUsecsPerDay;

public:
	static TimeSpan maxValue();
	static TimeSpan minValue();

public:
	TimeSpan(longlong usecs = 0);
	TimeSpan(int days, int hours, int mins, int secs, int msecs = 0, int usecs = 0);
	TimeSpan(const TimeSpan& other);
	~TimeSpan();

public:
	TimeSpan& operator=(const TimeSpan& other);
	TimeSpan operator+(const TimeSpan& other);
	TimeSpan operator-(const TimeSpan& other);
	TimeSpan& operator+=(const TimeSpan& other);
	TimeSpan& operator-=(const TimeSpan& other);	
	bool operator>(const TimeSpan& other);
	bool operator<(const TimeSpan& other);
	bool operator>=(const TimeSpan& other);
	bool operator<=(const TimeSpan& other);
	bool operator==(const TimeSpan& other);
	bool operator!=(const TimeSpan& other);

public:
	longlong dayPart() const;
	longlong hourPart() const;
	longlong minutePart() const;
	longlong secondPart() const;
	longlong millisecondPart() const;
	longlong microsecondPart() const;

	longlong totalDays() const;
	longlong totalHours() const;
	longlong totalMinutes() const;
	longlong totalSeconds() const;
	longlong totalMilliseconds() const;

	double exactDays() const;
	double exactHours() const;
	double exactMinutes() const;
	double exactSeconds() const;
	double exactMilliseconds() const;

private:
	longlong mSpan;
};
/*
============================================================
== DateTime
============================================================
*/
class DateTime
{
public:
	DateTime();
	DateTime(time_t calendarTime);
	DateTime(int year, int month, int date, int hour = 0, int minute = 0, int sec = 0);
	DateTime(const DateTime& other);
	~DateTime();

public:
	DateTime& operator=(const DateTime& other);
	DateTime operator+(const TimeSpan& span);
	DateTime operator-(const TimeSpan& span);
	DateTime& operator+=(const TimeSpan& span);
	DateTime& operator-=(const TimeSpan& span);
	TimeSpan operator-(const DateTime& other);
	bool operator==(const DateTime& other);
	bool operator!=(const DateTime& other);
	bool operator>(const DateTime& other);
	bool operator<(const DateTime& other);
	bool operator>=(const DateTime& other);
	bool operator<=(const DateTime& other);

public:
	time_t calendarTime() const;
	int year() const;
	int month() const;
	int date() const;
	int hour() const;
	int minute() const;
	int second() const;
	int dayOfWeek() const;
	int dayofYear() const;
	bool isLeapYear() const;
	String toString(const String& fmt = _T("YYYY-MM-DD hh-mm-ss"));
	
private:
	time_t mCalendarTime;
	tm* mBrokenTime;
};

_EndNamespace(Radix)

#endif//_RADIX_ARCHAISM_TIME_H_
